<?php
/**
 * 更新商品基础数据
 *
 */
$argv[1] = 'dev.fh.taoex.com';
$argv[2] = '2012-11-16 00:00:00';
$argv[3] = '2012-11-16 23:59:59';

$domain = $argv[1];
$sDate = time()-86400;//strtotime($argv[2]);
$eDate = time();//strtotime($argv[3]);


define('COMMAND_MODE', true);

set_time_limit(0);
define('LIB_DIR', dirname(__FILE__) . '/lib/');
require_once(LIB_DIR . 'api/taobao/order.php');
require_once(dirname(__FILE__) . '/lib/init.php');

updateGoods();

function updateGoods() {

	
	
	//类别type_id
	$type=array(
			"奶粉"=> 	2,
			"辅食"=> 	3,
			"营养品"=> 	4,
			"婴童服饰"=> 	5,
			"防尿用品"=> 	6,
			"车床椅"=> 	7,
			"玩具"=> 	8,
			"居家日用"=> 	9,
			"洗护用品"=> 	10,
			"妈妈用品"=> 	11,
			"图书音像"=> 	12,
			"喂养用品"=> 	13,
			"妈妈服饰"=> 	14,
			);
	//品牌brand_id
	$brand=array(
			"贝莱康"=> 	2,
			"新安怡"=> 	3,
			"宝贝可爱"=> 	4,
			"NUK"=> 	5,
			"美丽健"=> 	6,
			"明高"=> 	7,
			"爱宝氏"=> 	8,
			"LALA"=> 	9,
			"爱孕娇"=> 	10,
			"爱珍"=> 	11,
			"朗聪"=> 	12,
			"澳贝"=> 	13,
			"能力多"=> 	14,
			"古之极"=> 	15,
			"百乐麦"=> 	16,
			"帮宝适"=> 	17,
			"花王"=> 	18,
			"安琪"=> 	19,
			"葆婴"=> 	20,
			"比爱"=> 	21,
			"倍舒特"=> 	22,
			"得琪"=> 	23,
			"宝育堂"=> 	24,
			"大王"=> 	25,
			"迪孚"=> 	26,
			"帝药"=> 	27,
			"多美滋"=> 	28,
			"恩济堂"=> 	29,
			"方圆"=> 	30,
			"费雪"=> 	31,
			"风铃"=> 	32,
			"格兰宝"=> 	33,
			"格朗"=> 	34,
			"汉臣氏"=> 	35,
			"好孩子"=> 	36,
			"好女人"=> 	37,
			"好奇"=> 	38,
			"合生元"=> 	39,
			"和光堂"=> 	40,
			"亨氏"=> 	41,
			"魔笔小良"=> 	42,
			"黄色小鸭"=> 	43,
			"惠氏/启赋"=> 	44,
			"嘉宝"=> 	45,
			"布朗博士"=> 	46,
			"金盾"=> 	47,
			"金时尚"=> 	48,
			"开阳"=> 	49,
			"康贝"=> 	50,
			"乐儿宝"=> 	51,
			"妈咪宝贝"=> 	52,
			"马博士"=> 	53,
			"每伴"=> 	54,
			"美斯特伦"=> 	55,
			"美素"=> 	56,
			"美赞臣"=> 	57,
			"强生"=> 	58,
			"全元康"=> 	59,
			"雀巢"=> 	60,
			"日康"=> 	61,
			"乳加力"=> 	62,
			"生命阳光"=> 	63,
			"适宝康"=> 	64,
			"首儿"=> 	65,
			"硕士"=> 	66,
			"婷美"=> 	67,
			"维克斯"=> 	68,
			"维塔卡尼"=> 	69,
			"喜多"=> 	70,
			"喜加"=> 	71,
			"小霸王"=> 	72,
			"小白熊"=> 	73,
			"小龙哈彼"=> 	74,
			"小仙子"=> 	75,
			"雅培"=> 	76,
			"亚都"=> 	77,
			"阳光宝贝"=> 	78,
			"易简"=> 	79,
			"婴唯爱"=> 	80,
			"婴之侣"=> 	81,
			"优生妈咪"=> 	82,
			"智灵通"=> 	83,
			"郑玉巧"=> 	84,
			"水华青阳"=> 	85,
			"适婴坊"=> 	86,
			"时代公仔"=> 	87,
			"威凯"=> 	88,
			"奥吉康"=> 	89,
			"小婴孩"=> 	90,
			"小小孩"=> 	91,
			"康贝儿"=> 	92,
			"谷雨"=> 	93,
			"舒氏"=> 	94,
			"圣得贝"=> 	95,
			"福施福"=> 	96,
			"贝乐星"=> 	97,
			"米家"=> 	98,
			"贝乐宝"=> 	99,
			"天明珠"=> 	100,
			"康乐"=> 	101,
			
			"松达"=> 	102,
			"婴爽"=> 	103,
			"热销"=> 	104,
			"小皇帝"=> 	105,
			"海之雨"=> 	106,
			"贝比卡儿"=> 	107,
			"美婴美"=> 	108,
			"聪明学子"=> 	109,
			"少飞"=> 	110,
			"小企鹅"=> 	111,
			"贝贝卡索"=> 	112,
			"田园小蟋哥"=> 	113,
			"秀秀小兔"=> 	114,
			"小胖子"=> 	115,
			"开心霏凡"=> 	116,
			"快乐天地"=> 	117,
			"阿笨猫"=> 	118,
			"格丽雅"=> 	119,
			"依裤啦"=> 	120,
			"路雪"=> 	121,
			"亲亲我"=> 	122,
			"塔塔"=> 	123,
			"婴之宝"=> 	124,
			"侏罗纪"=> 	125,
			"鼎鑫"=> 	126,
			"口清口清"=> 	127,
			"安信"=> 	128,
			"好吉宝"=> 	129,
			"亲茶园"=> 	130,
			"好世界"=> 	131,
			"育康"=> 	132,
			"鼻朗"=> 	133,
			"嗳呵"=> 	134,
			"鲜果吧"=> 	135,
			"芭啦谷"=> 	136,
			"乳珍"=> 	137,
			"巧虎系列"=> 	138,
			"学子"=> 	139,
			"雨茹儿"=> 	140,
			"乐佳善优"=> 	141,
			"其他品牌"=> 	142,
			"星羽小丫"=> 	143,
			"童星"=> 	144,
			"惠步舒"=> 	145,
			"破壳"=> 	146,
			"蓓茵儿"=> 	147,
			"动感磁场"=> 	148,
			"中国书店"=> 	149,
			"嘟嘟啦"=> 	150,
			"迪尔"=> 	151,
			"康贝"=> 	152,
			"长虹"=> 	153,
			"润本"=> 	154,
			"亲润"=> 	155,
			"草芽儿"=> 	156,
			"唐绵"=> 	157,
			"孕之妮"=> 	158,
			"桂子飘香"=> 	159,
			"女之御"=> 	160,
			"十月天使"=> 	161,
			"安贝妮"=> 	162,
			"蓝贝"=> 	163,
			"蒂巴蕾"=> 	164,
			"安利"=> 	165,
			"新贝"=> 	166,
			"蒂巴蕾"=> 	167,
			"贝拉贝儿"=> 	168,
			"贝比"=> 	169,
			"迪士尼"=> 	170,
			"汇源"=> 	171,
			"苏菲"=> 	172,
			"巴托"=> 	173,
			"谷之爱"=> 	174,
			"安婴保"=> 	175,
			"婴佳宜"=> 	176,
			"班妮小兔"=> 	177,
			"贝乐堡"=> 	178,
			"其他"=> 	179,
			"莱薇妈妈"=> 	180,
			"良兴"=> 	181,
			"婴得利"=> 	182,
			"艾雪"=> 	183,
			"哈罗闪"=> 	184,
			"阳光七彩"=> 	185,
			"喜亲宝"=> 	186,
			"皮皮熊"=> 	187,
			"雅孕"=> 	188,
			"婴妮儿"=> 	189,
			"俏菓"=> 	190,
			"美德乐"=> 	191,
			"沐乐思"=> 	192,
			"优朵"=> 	193,
			"呼西贝"=> 	194,
			"家乐宝"=> 	195,
			"呼西贝"=> 	196,
			"思宝"=> 	197,
			"奇峰"=> 	198,
			"ABC"=> 	199,
			"巴布豆"=> 	200,
			"福乐儿"=> 	201,
			
			"卡洛塔妮"=> 	202,
			"法婴特"=> 	203,
			"乐婴堂"=> 	204,
			"热卖"=> 	205,
			"科尔达"=> 	206,
			"优贝乐"=> 	207,
			"金奇仕"=> 	208,
			"南国婴宝"=> 	209,
			"彼特的蜜蜂"=> 	210,
			"曼秀雷敦"=> 	211,
			"贝贝利安"=> 	212,
			"靓丽孕宝"=> 	213,
			"欢乐儿准妈咪"=> 	214,
			"幸福宝"=> 	215,
			"童泰"=> 	216,
			"可爱卡通"=> 	217,
			"顺口溜"=> 	218,
			"kiddy"=> 	219,
			"飘漾"=> 	220,
			"皇室乐儿宝"=> 	221,
			"笑巴喜"=> 	222,
			"喜洋洋"=> 	223,
			"塔塔"=> 	224,
			"易简"=> 	225,
			"贝贝卡西"=> 	226,
			"益百佳"=> 	227,
			"外贸"=> 	228,
			"Kacakid"=> 	229,
			"汇乐"=> 	230,
			"优贝"=> 	231,
			"菲爽宝贝"=> 	232,
			"熊猫量子"=> 	233,
			"童音童画"=> 	234,
			"花园宝宝"=> 	235,
			"婴妮儿"=> 	236,
			"纽瑞滋"=> 	237,
			"首儿"=> 	238,
			"欣海博远"=> 	239,
			"五星玩具"=> 	240,
			"优贝比"=> 	241,
			"GAP"=> 	242,
			"欧卡桑"=> 	243,
			"美之妈咪"=> 	244,
			"伊秀阁"=> 	245,
			"allwoo"=> 	246,
			"蕴香"=> 	247,
			"艾妮宝贝"=> 	248,
			"MAMA"=> 	249,
			"乔妮雅"=> 	250,
			"Lollipop"=> 	251,
			"伊秀阁"=> 	252,
			"女之御"=> 	253,
			"蓓茵儿"=> 	254,
			"琪孕儿"=> 	255,
			"考比"=> 	256,
			"漫普"=> 	257,
			"漫谱"=> 	258,
			"欧卡桑"=> 	259,
			"北斗"=> 	260,
			"KBM"=> 	261,
			"顶呱呱"=> 	262,
			"十月情"=> 	263,
			"草本原液"=> 	264,
			"草莓南瓜"=> 	265,
			"好娃娃"=> 	266,
			"佳洁士"=> 	267,
			"清华力合"=> 	268,
			"蓓氏"=> 	269,
			"本周活动"=> 	270,
			"高露洁"=> 	271,
			"纳爱斯"=> 	272,
			"红孩儿"=> 	273,
			"宝的宝的"=> 	274,
			"丹瑞贝贝"=> 	275,
			"特福芬"=> 	276,
			"天天学"=> 	277,
			"威露士"=> 	278,
			"蓝月亮"=> 	279,
			"炫洁"=> 	280,
			"其它"=> 	281,
			"菲爽宝贝"=> 	282,
			"裕牛"=> 	283,
			"竹之语"=> 	284,
			"有我就酷"=> 	285,
			"卡通"=> 	286,
			"沙虫"=> 	287,
			"犀牛超人"=> 	288,
			"伊之贝"=> 	289,
			"迎宝"=> 	290,
			"阳光儿童"=> 	291,
			"金贝尔"=> 	292,
			"星羽小Y"=> 	293,
			"盛哲卡"=> 	294,
			"纽曼思"=> 	295,
			"十月秀"=> 	296,
			"木玩世家"=> 	297,
			"贝拉米"=> 	298,
			"亚米"=> 	299,
			"显丹木"=> 	300,
			"一窝熊仔"=> 	301,			
			"思尔美"=> 	302,
			"LG"=> 	303,
			"旭贝尔"=> 	304,
			"皇室"=> 	305,
			"宜尚"=> 	306,
			"积分兑换"=> 	307,
			"天然世家"=> 	308,
			"优童"=> 	309,
			"乐高"=> 	310,
			"培乐多"=> 	311,
			"意多"=> 	312,
			"酷尾巴"=> 	313,
			"威尔贝鲁"=> 	314,
			"超级逗逗"=> 	315,
			"米奇丁当"=> 	316,
			"康盈"=> 	317,
			"传奇娃"=> 	318,
			"娃丽比"=> 	319,
			"小猪纳福"=> 	320,
			"皇家卫士"=> 	321,
			"顺口溜"=> 	322,
			"喜辽复"=> 	323,
			"多乐宝贝"=> 	324,
			"宝比珊"=> 	325,
			"保宁"=> 	326,
			"婴姿坊"=> 	327,
			"康馨儿"=> 	328,
			"如宝"=> 	329,
			"爱迪生"=> 	330,
			"小猪班纳"=> 	331,
			"基诺浦"=> 	332,
			"喜羊羊与灰太狼"=> 	333,
			"其他"=> 	334,
			"迪卡莱恩"=> 	335,
			"艾儿妈妈"=> 	336,
			"宜栖"=> 	337,
			"德萨"=> 	338,
			"顺清柔"=> 	339,
			"巴布豆"=> 	340,
			"爱国者"=> 	341,
			"宜栖"=> 	342,
			"梦狐"=> 	343,
			"优宝优贝"=> 	344,
			"luyookids"=> 	345,
			"宜栖"=> 	346,
			"七彩阳光"=> 	347,
			"卡西龙"=> 	348,
			"蟹蟹牛"=> 	349,
			"黄色小鸭"=> 	350,
			"葛莱"=> 	351,
			"艾乐贝贝"=> 	352,
			"利其尔"=> 	353,
			"阿普丽佳"=> 	354,
			"抱抱熊"=> 	355,
			"智高"=> 	356,
			"博士蛙"=> 	357,
			"徐福记"=> 	358,
			"好运宝贝"=> 	359,
			"贴心可儿"=> 	360,
			"贝安诺"=> 	361,
			"贝臣"=> 	362,
			"娃丽比"=> 	363,
			"三利"=> 	364,
			"亨艺开阳"=> 	365,
			"优伴"=> 	366,
			"DURR迪尔"=> 	367,
			"苏歌尔"=> 	368,
			"广迪"=> 	369,
			"全因爱"=> 	370,
			"BabySun"=> 	371,
			"蓝若水"=> 	372,
			"NEXT"=> 	373,
			"欧乐氏"=> 	374,
			"煜婴坊"=> 	375,
			"方广"=> 	376,
			"婴秀"=> 	377,
			"禧贝"=> 	378,
			"爱米艾咔"=> 	379,
			"安思培"=> 	380,
			"乐孕"=> 	381,
			"袋鼠仔仔"=> 	382,
			"煜婴坊"=> 	383,
			"Mari House"=> 	384,
			"丝蓓柔"=> 	385,
			"丹尼宝贝"=> 	386,
			"动力宝宝"=> 	387,
			"安奈儿"=> 	388,
			"宝贝世家"=> 	389,
			"just for kids"=> 	390,
			"神奇兔"=> 	391,
			"键安"=> 	392,
			"小阿哥"=> 	393,
			"凯诗风尚"=> 	394,
			"家好月圆"=> 	395,
			"蒂乐"=> 	396,
			"爱护"=> 	397,
			"帕奇"=> 	398,
			"BabyGap"=> 	399,
			"帕傲"=> 	400,
			"Colorland"=> 	401,			
			"杜曼"=> 	402,
			"喜宝"=> 	403,
			"美羚"=> 	404,
			"舒珀"=> 	405,
			"红遍天"=> 	406,
			"福贝贝"=> 	407,
			"贝安诺"=> 	408,
			"迪纳朗星"=> 	409,
			"品维"=> 	410,
			"英纷"=> 	411,
			"富罗迷"=> 	412,
			"Great格雷特"=> 	413,
			"伊利"=> 	414,
			"润心"=> 	415,
			"文盛"=> 	416,
			"莫夫"=> 	417,
			"赛儿乐"=> 	418,
			"泰迪熊"=> 	419,
			"启航"=> 	420,
			"邦宝"=> 	421,
			"爱音"=> 	422,
			"百代适"=> 	423,
			"诺尼亚"=> 	424,
			"挪威"=> 	425,
			"伊威"=> 	426,
			"法拉利"=> 	427,
			"迈高"=> 	428,
			"中亲"=> 	429,
			"明治"=> 	430,
			"凯诗家纺"=> 	431,
			"贝亲"=> 	432,
			"Lancome兰蔻"=> 	433,
			"大卫杜夫"=> 	434,
			"范思哲"=> 	435,
			"浪凡"=> 	436,
			"菲拉格慕"=> 	437,
			"伊丽莎白雅"=> 	438,
			"雅芳"=> 	439,
			"卡文克莱"=> 	440,
			"驿动美"=> 	492,
			"百代适/宝得适"=> 	2777,
			"Past Familie 帕特菲力"=> 	4909,
			"卡蒂卡蒂"=> 	5480,
			);
			
 
	
			$db = kernel::database();

			$row = 0;
			$n=0;
			$e=0;
			$handle = fopen("data/product1.csv","r");
			while ($data = fgetcsv($handle, 1000, ",")) {
				$num = count($data);
				//echo "			$num fields in line $row:			\n";
				$row++;
				// 				for ($c=0; $c < $num; $c++) {
				// 					echo $data[$c] . "
				// 					\n";
				// 				}


				$bc=$data[0];
				$mktprice=$data[1];
				$wholesale=$data[2];
				$cost=$data[3];
				//$type_id = $data[5];
				//$brand_id=$data[4];
				$safe_store=2;
				$store=$data[4];
				$product_name=$data[5];
				if(!$safe_store)$safe_store=1;

				$sql = "select count(*) as _count from `sdb_ome_goods` where bn='$bc'";
				$r = $db->select($sql);
				$a = intval($r[0]['_count']);
				//echo $a.$sql;
				//continue;
				if($a >0){
					//更新商品价格
					$sql1 = "update `sdb_ome_goods` set mktprice='$mktprice',wholesale='$wholesale',cost='$cost'   where  bn='$bc'";
					echo "已更新,".$product_name.','.$rs.",".$bc."\n";
					$n++;

					//更新货品库存
					$sql2 = "update `sdb_ome_products` set  store=$store,mktprice='$mktprice',wholesale='$wholesale',cost='$cost'  where  bn='$bc'";
					$sql3 = "update `sdb_ome_branch_product` set  store=$store, safe_store=$safe_store  where  product_id=(select product_id from sdb_ome_products where  bn='$bc')";

					if($db->exec($sql1)){
						if($rs = $db->affect_row()){
							$db->exec($sql2);
							$db->exec($sql3);

						}
					}else{
						echo "错误,".$product_name.','.','.$bc."\n";
						$e++;
					}
				}else{
						
					echo "未更新,".$product_name.','.$rs.",".$bc."\n";

				}

				
			}
			fclose($handle);
		 
			
	 
				
	 
			echo "更新".$n."共".$row."错误".$e;
	 
			
}